package com.burpee.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.Addfile;
import com.burpee.ui.Coordinate;

@Repository(value="coordinateDao")
public class CoordinateDaoImpl implements CoordinateDao {

	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}

	public List<Coordinate> list() {

		List<Coordinate> list=null;

		try {
			list = sqlSessionTemplate.selectList("coordinatelist");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	public Coordinate view(Coordinate coordinate) {
		
		Coordinate coordinateview=new Coordinate();

		try {
			coordinateview = sqlSessionTemplate.selectOne("coordinateview",coordinate);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return coordinateview;
	}

	public int add(Coordinate coordinate) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("coordinateadd",coordinate);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int modify(Coordinate coordinate) {
		
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("coordinatemodify",coordinate);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int remove(Coordinate coordinate) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("coordinateremove",coordinate);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
